<script src="<?php echo base_url().'assets/js/jquery.tablesorter.min.js'; ?>" type="text/javascript"></script>
<script type="text/javascript">
	$(function(){
		$('#delete').click(function(){
			var n
			n = $("input[name='checkid[]']:checked").length
			if( n <= 0 ) {
				alert('Please select users from the list to delete.')
				return false
			} else {
				if ( confirm('Are you sure you want to delete records?') == true ){
					$('#task').val('delete')
					$('#adminForm').submit()
				} else {
					return false
				}
			}
			return false
		})

		$('#checkall').click(function(){
			var n
			n = $("input[name='checkid[]']").length
			for( var i=0; i<n; i++){
				if( $("#checkall").is(":checked") ){
					$("input[name='checkid[]']").attr('checked', true);
				} else {
					$("input[name='checkid[]']").attr('checked', false);
				}
			}
			$("#checkboxall").removeClass("checkall").addClass("uncheckall");
		})

		$("#adminTable").tablesorter({
			 headers: {
               0: {sorter: false},
               1: {sorter: false},
               2: {sorter: false},
               7: {sorter: false},
               8: {sorter: false}
             }
		})

	})


</script>
<div class="content">
	<?php echo form_open('admin/users/index', array('name'=>'adminForm','id'=>'adminForm')); ?>
	<div id="top-heading">
		<div id="h-links">
			<?php
			echo anchor(site_url(). '/admin/users/create', 'Create User', 'id="add-new" class="button"');
			echo anchor('#', 'Delete', 'id="delete" class="button"');
			echo form_input('search_text','','id="search-text"');
			echo anchor('#','Search Users', 'id="search-btn" class="button"');
			?>
		</div>
		<div id="pagination">
		<?php echo $pagination; ?>
		</div>
	</div>

	<?php
	$this->message->display();
	$this->load->library('table');
	$tmpl = array( 'table_open' => '<table border="1" class="admin-table" id="adminTable">' );
	$this->table->set_template($tmpl);
	$h = array();
	$h[] = array('data' => '#', 'width' => '3%');
	$h[] = array('data' => '<input type="checkbox" id="checkall" class="inputbox"/>', 'width' => '3%');
	$h[] = array('data' => 'Edit', 'width' => '5%');
	$h[] = array('data' => 'Username', 'width' => '15%');
	$h[] = array('data' => 'Name');
	$h[] = array('data' => 'Email');
	$h[] = array('data' => 'Level');
	$h[] = array('data' => 'Active', 'width' => '5%');
	$h[] = array('data' => 'Online', 'width' => '5%');
	$h[] = array('data' => 'ID', 'width' => '5%');

	$this->table->set_heading($h);

	$table_row = array();
	$i = 1;
	foreach ($users_qry_limited->result() as $user){
		$table_row = null;
		$table_row[] = $i++;
		$table_row[] = '<input type="checkbox" name="checkid[]" value="'.$user->userid.'" class="checkbox" />';
		$table_row[] = anchor('admin/users/edit/'.$user->userid, 'Edit');
		$table_row[] = $user->username;
		$this->load->helper('User_helper');
		$table_row[] = User_Helper::getFullName($user->userid);
		$table_row[] = $user->email;
		//$this->load->helper('Select_helper');
		$table_row[] = ucfirst($user->type);
		$this->load->helper('Boolean_helper');
		$table_row[] = Boolean_helper::status($user->status, true);
		$table_row[] = Boolean_helper::online($user->online);
		$table_row[] = $user->userid;
		$this->table->add_row($table_row);
	}
	echo $this->table->generate();
	?>
	<input type="hidden" name="task" id="task" />
	<?php echo form_close();
	?>

</div>
